home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / fonted12.zip / PRINTAT.CPP < prev    next >
C/C++ Source or Header  |  1992-09-23  |  2KB  |  63 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include <conio.h>
  4.  
  5. typedef unsigned int  word;
  6. typedef unsigned char byte;
  7.  
  8. #include "font6x6s.h"
  9.  
  10. /* informations about active font */
  11. char *fontptr = font6x6s; // pointer to active font
  12. byte width = 6;                // width of char
  13. byte height = 6;            // height of char
  14. byte widthb = 1;            // width in bytes
  15. byte shifts = 1;            // in font are used shifts
  16. byte startchar = 0;        // first char from font
  17. byte endchar = 127;        // last char from font
  18. word firstshift = (((endchar-startchar)+1)*height*widthb);
  19. //   ^^^ offset of first shift in font
  20.  
  21. #define videoofs(x, y) ((y * 320) + x)
  22. #define videoseg 0xA000
  23. #define putpixel(x, y, color) pokeb(videoseg, videoofs((x), (y)), color)
  24.  
  25. void putch(word x, word y, char ch, byte col1 = 15, byte col2 = 0)
  26. {
  27.     byte a, b, w = shifts ? fontptr[firstshift + ch] : width;
  28.     byte bit[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
  29.  
  30.     for (a = 0; a < height; a++)
  31.         for (b = 0; b < w; b++)
  32.             if ((fontptr[(ch*height*widthb) + (a*widthb) + (b > 7 ? 1 : 0)] & bit[b > 7 ? b - 8 : b]))
  33.                 putpixel(x + b, y + a, col1);
  34.             else
  35.                 if (col2 != 255)
  36.                     putpixel(x + b, y + a, col2);
  37. }
  38.  
  39. void printat(word x, word y, char *text, byte col1 = 15, byte col2 = 0)
  40. {
  41.     word a, xx = x, yy = y;
  42.     for (a = 0; a < strlen(text); a++)
  43.         switch (text[a]) {
  44.             case 10    :    yy += height;
  45.                                 xx = x;
  46.                                 break;
  47.             default:    putch(xx, yy, text[a] - startchar, col1, col2);
  48.                                 xx += shifts ? fontptr[firstshift + (text[a]-startchar)] : width;
  49.                                 break;
  50.         };
  51. }
  52.  
  53. void main()
  54. {
  55.     asm mov ax, 0013h   // int vga (13h) mode
  56.     asm int 10h
  57.     printat(1, 1, "Hello world!", 1, 0);
  58.     printat(0, 0, "Hello world!", 4, 255);
  59. // if color of background is 255 then background of text won't be printed
  60.     getch();
  61.     asm mov ax, 0003h
  62.     asm int 10h
  63. }